#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    bool IsLetter(string& s, int i)
    {
        if ((s[i] >= 'a' && s[i] <= 'z') || (s[i] >= 'A' && s[i] <= 'Z'))
            return true;
        return false;
    }
    string reverseOnlyLetters(string s) {
        int left = 0, right = s.size() - 1;
        while (left < right)
        {
            while (left < right && !IsLetter(s, left)) ++left;
            while (left < right && !IsLetter(s, right)) --right;
            swap(s[left], s[right]);
            ++left; --right;
        }
        return s;
    }
};